package com.zikao.config.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author: Likaisheng
 * @Description: 该拦截器不用于处理用户的认证和授权，仅仅处理一些与用户相关的操作。比如，将用户的信息放入session中，供各个模块使用。
 * @Date: Created in 15:38:25 2021-03-05
 * @Modified By:
 */
@Slf4j
public class UserInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 由于项目中引入了shiro,shiro自带session,shiro的ShiroHttpServletRequest替换了原生的HttpServletRequest,
        // 导致户第一次访问网站时，系统不会自动生成session
        HttpSession session = request.getSession();
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}